import axios from "axios"
import { ElMessage } from "element-plus"
const service = axios.create({
    baseURL: "http://v3.web-jshtml.cn/api",
    timeout: 5000
})

// 请求拦截
service.interceptors.request.use(function (config) {
    return config
}, function(error) {
    return Promise.reject(error)
})

// 响应拦截
service.interceptors.response.use(function (response) {
    return Promise.resolve(response.data)
}, function (error) {
    const errorData = JSON.parse(error.request.response)
    if (errorData.message) {
        ElMessage({
            message: "http状态码400错误",
            type: "error"
        })
    }
    return Promise.reject(error)
})

export default service